using SPI.AgentServer.Models;
using Swashbuckle.AspNetCore.Filters;

namespace SPI.AgentServer.Examples;

/// <summary>
/// 查询请求示例提供器
/// </summary>
public class QueryRequestExample : IMultipleExamplesProvider<QueryRequest>
{
    public IEnumerable<SwaggerExample<QueryRequest>> GetExamples()
    {
        // 示例1：简单统计查询
        yield return SwaggerExample.Create(
            "简单统计",
            new QueryRequest
            {
                Query = "用户表有多少条记录",
                SessionId = "session-001",
                DatabaseName = "Main"
            }
        );

        // 示例2：时间范围查询
        yield return SwaggerExample.Create(
            "时间范围查询",
            new QueryRequest
            {
                Query = "查看最近7天的订单数量",
                SessionId = "session-002",
                DatabaseName = "Sales"
            }
        );

        // 示例3：复杂统计查询
        yield return SwaggerExample.Create(
            "复杂统计",
            new QueryRequest
            {
                Query = "统计每个部门的平均工资，按工资降序排列",
                SessionId = "session-003",
                DatabaseName = "HR",
                Context = new Dictionary<string, object>
                {
                    { "department_filter", "active" },
                    { "include_bonus", true }
                }
            }
        );

        // 示例4：表结构查询
        yield return SwaggerExample.Create(
            "查看表结构",
            new QueryRequest
            {
                Query = "显示产品表的结构"
            }
        );

        // 示例5：条件查询
        yield return SwaggerExample.Create(
            "条件查询",
            new QueryRequest
            {
                Query = "查找年龄大于30岁的用户，显示姓名和邮箱",
                DatabaseName = "Main"
            }
        );
    }
}

/// <summary>
/// 查询响应示例提供器
/// </summary>
public class QueryResponseExample : IExamplesProvider<QueryResponse>
{
    public QueryResponse GetExamples()
    {
        return new QueryResponse
        {
            Success = true,
            Summary = "查询成功，共找到156条订单记录",
            Data = new
            {
                columns = new[] { "order_date", "order_count", "total_amount" },
                rows = new[]
                {
                    new { order_date = "2025-10-09", order_count = 23, total_amount = 45678.90 },
                    new { order_date = "2025-10-10", order_count = 18, total_amount = 32456.50 },
                    new { order_date = "2025-10-11", order_count = 25, total_amount = 56789.00 },
                    new { order_date = "2025-10-12", order_count = 30, total_amount = 67890.25 },
                    new { order_date = "2025-10-13", order_count = 22, total_amount = 43210.80 },
                    new { order_date = "2025-10-14", order_count = 28, total_amount = 54321.60 },
                    new { order_date = "2025-10-15", order_count = 10, total_amount = 23456.70 }
                },
                hasMore = false
            },
            Errors = new List<string>(),
            Metadata = new QueryMetadata
            {
                SessionId = "session-001",
                ExecutionTimeMs = 245,
                ExecutedSql = "SELECT DATE(created_at) as order_date, COUNT(*) as order_count, SUM(amount) as total_amount FROM orders WHERE created_at >= DATEADD(day, -7, GETDATE()) GROUP BY DATE(created_at) ORDER BY order_date",
                UsedTools = new List<string> { "execute_sql" },
                RowCount = 7
            }
        };
    }
}







